package cn.com.cetccst.sdk.modelbase;

import static cn.com.cetccst.sdk.modelbase.ConstantsAPI.COMMAND_SEND_AUTH;
import static cn.com.cetccst.sdk.modelbase.ConstantsAPI.COMMAND_UNKNOWN;
import static cn.com.cetccst.sdk.modelbase.ConstantsAPI.SSAPI_COMMAND_TYPE;

import android.os.Bundle;

import cn.com.cetccst.sdk.modelbiz.SendAuth;

public abstract class BaseResp {
    public static final String SSAPI_BASERESP_ERRORCODE = "ssapi_baseresp_errorcode";
    public static final String SSAPI_BASERESP_ERRORSTR = "ssapi_baseresp_errorstr";
    public static final String SSAPI_BASERESP_TRANSACTION = "ssapi_baseresp_transaction";

    private int type = COMMAND_UNKNOWN;
    public int errorCode;
    public String errorStr;
    public String transaction;

    public BaseResp(int type) {
        this.type = type;
    }

    public int getType() {
        return type;
    }

    public void toBundle(Bundle bundle) {
        bundle.putInt(SSAPI_COMMAND_TYPE, this.getType());
        bundle.putInt(SSAPI_BASERESP_ERRORCODE, errorCode);
        bundle.putString(SSAPI_BASERESP_ERRORSTR, errorStr);
        bundle.putString(SSAPI_BASERESP_TRANSACTION, transaction);
    }

    public void fromBundle(Bundle bundle) {
        type = bundle.getInt(SSAPI_COMMAND_TYPE);
        errorCode = bundle.getInt(SSAPI_BASERESP_ERRORCODE);
        errorStr = bundle.getString(SSAPI_BASERESP_ERRORSTR);
        transaction = bundle.getString(SSAPI_BASERESP_TRANSACTION);
    }

    public boolean checkArgs() {
        return true;
    }

    public static BaseResp createRespByType(int type) {
        switch (type) {
            case COMMAND_SEND_AUTH:
                return new SendAuth.Resp();
            default:
                return new UnknownBaseResp();
        }
    }

    public interface ErrCode {
        //opensdk_错误类别_错误码
        int ERR_OK = 1_00_000;

        //通用错误
        int ERR_NO_NETWORK = 1_00_001,
                ERROR_OPENSDK_VERSION_TOO_LOW = 1_00_002,
                ERR_NOT_SUPPORT = 1_00_003,
                ERR_WORK_BENCH_ERROR = 1_00_004,
                ERR_PARAMETER_NULL = 1_00_005,
                ERR_SDK_ERROR = 1_00_006;
        //认证相关
        int ERR_AUTH_FAILED = 1_01_001,
                ERR_USER_CANCEL = 1_01_002,
                ERR_USER_DENIED = 1_01_003,
                ERR_NO_USER = 1_01_004;
        //app配置
        int ERR_APP_KEY_NULL = 1_02_001,
                ERR_APP_NOT_ADD = 1_02_002,
                ERROR_APP_KEY_ERROR = 1_02_003,
                ERROR_APP_NOT_INSTALL = 1_02_004;

        //权限错误
        int ERROR_PERMISSION_WRITE_SDCARD = 1_03_001,
                ERROR_PERMISSION_LOCATION = 1_03_002,
                ERROR_PERMISSION_CAMERA = 1_03_003;
        //jssdk相关
        int ERROR_REGISTER_FAILED = 1_04_001,
                ERROR_UNREGISTER_FAILED = 1_04_002,
                ERROR_FILE_DOWNLOADED_FAILED = 1_04_003,
                ERROR_FILE_CANCEL_DOWNLOAD = 1_04_004;
    }

    @Override
    public String toString() {
        return "BaseResp{" +
                "type=" + type +
                ", errorCode=" + errorCode +
                ", errorStr='" + errorStr + '\'' +
                ", transaction='" + transaction + '\'' +
                '}';
    }
}
